/**
 * <p>功能:系统管理模块-权限管理-角色管理 <p>
 * @extends Wys.basic.BaseView
 * @author wys
 */
Ext.define('Jason.view.protal.module.systemManager.right.roles.UserToRoleView', {
    extend: 'Ext.container.Container',
    xtype: 'systemManager_rolesToUser_usersView',
    requires: [
        'Ext.panel.Panel',
        'Wys.form.field.SearchField',
        'Ext.plugin.Responsive',
        'Ext.button.Button',
        'Ext.layout.container.Accordion',
        'Wys.utils.Config',
        'Wys.form.BaseWindow',
        'Jason.store.protal.module.systemManager.right.roles.RoleStore',
        'Jason.store.protal.module.systemManager.right.users.UserRoleStore',
        'Jason.view.protal.module.systemManager.right.roles.ViewModel',
        'Jason.view.protal.module.systemManager.right.roles.MainCtrl'
    ],
    controller: 'right_role_MainViewCtrl',
    viewModel: { type: 'roles_MainViewModel' },
    layout: {
        type: 'hbox',
        align: 'stretch'
    },
    items: [{
        xtype: 'treepanel',
        ui: 'light', border: true,
        itemId: 'haveRightByRoleView',
        title: '组织机构',
        iconCls: 'fa fa-folder-open-o',
        collapsible: false,
        collapsed: false,
        flex: 3,
        autoScroll: true,
        listeners: {
            itemclick: function (grid, record) {
                var userToRoleUserView = grid.up('window').down('#rolesUserGrid');
                userToRoleUserView.setTitle("【" + record.get('deptname') + "】用户列表");
                userToRoleUserView.load({
                    deptcode: record.get('id')
                })
            }
        },
        tools: [{
            type: 'refresh',
            tooltip: '刷新系统模块列表',
            handler: function (event, toolEl, panelHeader) {
                this.up('treepanel').getStore().reload();
            }
        }],
        split: false,
        bind: '{leftMenuTreeStoreByDept}',
        columnLines: false
    },
    {
        xtype: 'panel',
        ui: 'light',
        margin: '0 0 0 4',
        flex: 7,
        layout: 'fit',
        cls: 'pages-faq-container shadow-panel',
        items: [{
            xtype: 'baseView',
            ui: 'light',
            title: '用户列表',
            iconCls: 'fa fa-users',
            itemId: 'rolesUserGrid',
            //                flex: 1,
            enabledMark: false,
            dockedItems: [{
                xtype: 'pagingtoolbar',
                enabledMoreOpt: true,
                isShow: false,
                bind: '{userGridStore}',
                dock: 'bottom'
            }],
            bind: '{userGridStore}',
            columns: [
                { xtype: 'rownumberer', text: '序号', align: 'center', width: 50 },
                { text: '姓名', dataIndex: 'realname', minWidth: 100, flex: 2 },
                { text: '帐号', dataIndex: 'loginname', minWidth: 100, flex: .2 },
                {
                    text: '操作', width: 47, xtype: 'command', align: 'center',
                    commands: [
                        { command: "preview", text: '<i class="fa fa-arrow-right fa-lg"></i>', tooltip: { text: '分配' }, cls: 'radiusBtn command-info-color' }
                    ],
                    listeners: {
                        prepareCommands: function (self, gridRef, commands, record, row) {

                        },
                        command: function (item, command, record) {
                            var win = item.up('window');
                            EUtil.RS({
                                url: reqUrl.sys.user.userRole.create,
                                params: {
                                    usercode: record.id,
                                    rolecode: win.roleCode
                                },
                                callback: function (resp) {
                                    if (resp.success) {
                                        EUtil.showSuccess('为角色【' + win.rolename + '】分配用户成功');
                                        win.parentView.refresh();
                                    } else {
                                        EUtil.showError(resp.msg_info);
                                    }
                                }
                            });
                        }
                    }
                }
            ]
        }]
    }]
});